<?php

class News extends CActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return 'news';
	}

	public function rules()
	{
		return array(
      array('modified_at','safe'),
			array('subject, content, member_id', 'required'),
			array('member_id', 'numerical', 'integerOnly'=>true),
			//array('subject', 'length', 'max'=>2000),
			//array('content', 'length', 'max'=>2000),
			array('id, subject, content, created_at, member_id', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
      'member' => array(self::BELONGS_TO, 'Members', 'member_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'subject' => 'Subject',
			'content' => 'Content',
			'created_at' => 'Created At',
			'member_id' => 'Member',
		);
	}

	public function search($keyword)
	{
		$criteria=new CDbCriteria;
		$criteria->compare('subject',$keyword,true);
		$criteria->compare('content',$keyword,true);
    $news = News::model()->findAll($criteria);

		return $news;
	}
}